package 代码记录.指定公司代码练习记录.西安.分值200分.分支200分未做;

import java.util.Scanner;
import java.util.TreeSet;

/**
 * @author zx
 * @create 2023-07-11 20:57
 * 未星标
 */
public class 考古学家 {
    private static final TreeSet<String> set = new TreeSet<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String part = sc.nextLine();
        String[] parts = part.split(" ");
        solve(0, parts);
        for (String str : set) {
            System.out.println(str);
        }
    }
    private static void solve(int index, String[] str) {
        if (index == str.length) {
            StringBuilder sb = new StringBuilder();
            for (String s : str) {
                sb.append(s);
            }
            if (!sb.toString().isEmpty()) {
                set.add(sb.toString());
            }
            return;
        }
        for (int i = index; i < str.length; ++i) {
            swap(str,i,index);
            solve(index + 1, str);
            swap(str,i,index);
        }

    }
    private static void swap(String[] arr,int i, int j) {
        String temp = arr[j];
        arr[j] = arr[i];
        arr[i] = temp;
    }
}
